package com.leetcode.algorithm.common;

public class ListNodeUtils {

	public static ListNode of(int[] arr) {
		ListNode sentinel = new ListNode();
		ListNode prev = sentinel;
		for (int i = 0; i < arr.length; i++) {
			prev.next = new ListNode(arr[i]);
			prev = prev.next;
		}
		return sentinel.next;
	}

	public static boolean isSame(ListNode head, int[] arr) {
		return isSame(head, of(arr));
	}

	public static boolean isSame(ListNode node1, ListNode node2) {
		if (node1 == null || node2 == null) {
			return node1 == node2;
		}
		return node1.val == node2.val && isSame(node1.next, node2.next);
	}

}